﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Microsoft.Win32;

namespace PTExpress.Views
{
    /// <summary>
    /// Interaction logic for ucPictureBox.xaml
    /// </summary>
    public partial class ucPictureBox : UserControl
    {
        public ucPictureBox()
        {
            InitializeComponent();
        }

        public ucPictureBox(string img)
        {
            ImgSource = img;
            ImageSource = ImgSource;
            InitializeComponent();
        }

        public string ImageSource = null;

        public string ImgSource
        {
            get { return (string)GetValue(ImgSourceProperty); }
            set { SetValue(ImgSourceProperty, value); ImageSource = value; }
        }

        // Using a DependencyProperty as the backing store for ImgSource.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty ImgSourceProperty =
            DependencyProperty.Register("ImgSource", typeof(string), typeof(ucPictureBox), new UIPropertyMetadata("Images\\NoPic.png"));



        public Visibility HidenValue
        {
            get { return (Visibility)GetValue(HidenValueProperty); }
            set { SetValue(HidenValueProperty, value); }
        }

        // Using a DependencyProperty as the backing store for HidenValue.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty HidenValueProperty =
            DependencyProperty.Register("HidenValue", typeof(Visibility), typeof(ucPictureBox), new UIPropertyMetadata(Visibility.Collapsed));

        private void UcPictureBox_Loaded(object sender, RoutedEventArgs e)
        {
            //ImgSource = "Images\\NoPic.png";
        }

        private void btnSelectPicture_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.DefaultExt = ".jpg";
            dlg.Multiselect = false;

            if (dlg.ShowDialog() == true)
            {
                ImgSource = dlg.FileName;
                ImageSource = ImgSource;
                HidenValue = Visibility.Collapsed;
            }
        }

        private void btnDelPicture_Click(object sender, RoutedEventArgs e)
        {
            ImgSource = "Images\\NoPic.png";
            ImageSource = null;
        }

        private void Image_MouseEnter(object sender, MouseEventArgs e)
        {
            HidenValue = Visibility.Visible;
        }

        private void Image_MouseLeave(object sender, MouseEventArgs e)
        {
            HidenValue = Visibility.Collapsed;
        }
    }
}
